package staticindex;

public class ArrayUtil {
    //私有化构造方法
    private ArrayUtil(){}
    //目的:不让外界创建对象

   //foreach
    public static void foreach(int []arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    //sort
    public static void sort(int []arr){
        for (int i = 0; i <arr.length-1 ; i++) {
            for (int j = 0; j <arr.length-1 ; j++) {
                if(arr[j]>arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.print("{");


        for(int item : arr){
            if(item!=arr[arr.length-1]){
                System.out.print(item+" ,");
            }else{
                System.out.print(item);
            }
        }
        System.out.print("}");
    }
    //getAverage()
    public static int getAverage(int []arr){
        int sum=0;
        for (int i = 0; i <arr.length ; i++) {
            sum+=arr[i];
        }
        return sum/arr.length;
    }
}
